package com.yuxl.ai.spg.controller;

import com.yuxl.ai.spg.entity.AiSpgSchema;
import com.yuxl.ai.spg.service.AiSpgSchemaService;
import com.yuxl.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@Tag(name = "知识图谱:描述")
@RequestMapping("/ai/spg/chema")
@RestController
public class AiSpgSchemaController {
    @Resource
    private AiSpgSchemaService aiSpgSchemaService;

    @Operation(summary = "创建知识图谱描述")
    @PostMapping
    public Mono<AiSpgSchema> create(@RequestBody AiSpgSchema entity) {
        return aiSpgSchemaService.create(entity);
    }

    @Operation(summary = "根据ID查询知识图谱描述")
    @GetMapping("/{id}")
    public Mono<R<AiSpgSchema>> getById(@Parameter(description = "知识图谱描述ID") @PathVariable Long id) {
        return aiSpgSchemaService.findById(id)
                .map(R::ok);
    }

    @Operation(summary = "更新知识图谱描述")
    @PutMapping
    public Mono<R<AiSpgSchema>> updateById(@RequestBody AiSpgSchema entity) {
        return aiSpgSchemaService.updateById(entity)
                .map(R::ok);
    }

    @Operation(summary = "删除知识图谱描述")
    @DeleteMapping("/{id}")
    public Mono<R<Void>> deleteById(@Parameter(description = "知识图谱描述ID") @PathVariable Long id) {
        return aiSpgSchemaService.deleteById(id)
                .thenReturn(R.ok());
    }

    @Operation(summary = "条件查询知识图谱描述列表")
    @PostMapping("/list")
    public Mono<R<List<AiSpgSchema>>> list(@RequestBody AiSpgSchema entity) {
        return aiSpgSchemaService.list(entity)
                .collectList()
                .map(R::ok);
    }

    @Operation(summary = "统计知识图谱描述数量")
    @PostMapping("/count")
    public Mono<R<Integer>> count(@RequestBody AiSpgSchema entity) {
        return aiSpgSchemaService.count(entity)
                .map(R::ok);
    }

    @Operation(summary = "分页条件查询知识图谱描述")
    @PostMapping("/{page}/{size}/page")
    public Mono<R<List<AiSpgSchema>>> page(
            @RequestBody AiSpgSchema entity,
            @PathVariable int page,
            @PathVariable int size
    ) {
        return aiSpgSchemaService.page(entity, page, size)
                .collectList()
                .map(R::ok);
    }
}
